﻿using PureMVC.Interfaces;
using PureMVC.Patterns.Mediator;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewRoleViewMediator : Mediator
{
    public static new string NAME = "NewRoleViewMediator";

    public NewRoleViewMediator() : base(NAME)
    {

    }

    public void SetView(NewRoleView view)
    {
        ViewComponent = view;
        //关闭按钮的事件监听
        view.btnClose.onClick.AddListener(() => {
            SendNotification(PureNotification.HIDE_PANEL,GameFacade.Instance.RetrieveMediator(NewRoleViewMediator.NAME));
        });
        //升级按钮的事件监听
        view.btnLevUp.onClick.AddListener(()=> {
            SendNotification(PureNotification.LVE_UP);
        });
    }

    public override string[] ListNotificationInterests()
    {
        return new string[] {
            PureNotification.UPDATE_PLAYER_INFO,
            //要监听其他的就在这后面加
        };   
    }

    public override void HandleNotification(INotification notification)
    {
        switch (notification.Name)
        {
            case PureNotification.UPDATE_PLAYER_INFO:
                //因为可能出现界面被移除了但是mediator还在监听 需要判断下界面不为空再处理
                if (ViewComponent!=null)
                {
                    (ViewComponent as NewRoleView).UpdateInfo(notification.Body as PlayerDataObj);
                }
                break;
        }
    }

    public override void OnRegister()
    {
        base.OnRegister();  
    }
}
